package com.ruoyi.flow.adapter;

import com.ruoyi.common.satoken.utils.LoginHelper;
import com.ruoyi.flow.domain.vo.WarmFlowInteractiveTypeVo;
import org.dromara.warm.flow.core.dto.FlowParams;
import org.dromara.warm.flow.core.enums.CooperateType;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 转办适配器
 */
@Component
public class TransferAdapter extends AbstractWarmFlowAdapter implements WarmFlowAdapter {
    @Override
    public boolean isAdapter(Integer warmFlowType) {
        return Objects.equals(CooperateType.TRANSFER.getKey(), warmFlowType);
    }

    @Override
    public boolean adapter(WarmFlowInteractiveTypeVo obj) {
        Long taskId = obj.getTaskId();
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        String userId = String.valueOf(sysUser.getUserId());
        FlowParams flowParams = new FlowParams()
            .handler(LoginHelper.getUserId()+"")
            .permissionFlag(permissionList())
            .addHandlers(obj.getAddHandlers())
            .message(this.type(obj.getOperatorType()));

        return super.taskService.transfer(taskId, flowParams);
    }
}
